package com.zzy.blog.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionSupport;
import com.zzy.blog.dao.pojo.Memory;
import com.zzy.blog.dao.pojo.User;
import com.zzy.blog.service.LoginService;

public class LoginAction extends ActionSupport{
	
	private static final Log LOG = LogFactory.getLog(LoginAction.class);
	
	private User user;
	private LoginService loginService;

	public String login() {
		
		//测试内存数据库 hibernate连接
		List<Memory> memorys = loginService.getMemory();
		for(Memory m : memorys){
			System.out.println(m);
		}
		
		
		//测试内存数据库事务
		Memory m = new Memory();
		m.setA("a");
		m.setB("a");
		m.setC("a");
		m.setD("a");
		m.setE("a");
		m.setF("a");
		m.setG("a");
		m.setH("a");
		m.setI("a");
		loginService.save(m);
		
		//测试一般数据库事务
		loginService.save(user);
		
		//测试action和jsp互相注入数据
		LOG.info("注入user: " + user);
//		portal里面的搞法...
//		LoginService loginService =  (LoginService) BeanFactory.getBeanName("loginService");
		if(loginService.checkUser(user)) {
			return SUCCESS;
		}else{
			return ERROR;
		}
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}
	
	public LoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	
}
